package com.qubuyer.business.auth.viewmodel

import androidx.lifecycle.MutableLiveData
import com.qubuyer.business.auth.model.AuthModel
import com.qubuyer.core.anno.AutoInject
import com.qubuyer.core.framework.BaseViewModel
import com.qubuyer.core.http.RetrofitCall
import com.qubuyer.repository.entitys.LoginEntity

/**
 * Author: linwg
 * Time: 2021/3/11 0011
 * Description:
 */
class RegisterViewModel : BaseViewModel() {

    @AutoInject
    private val authModel = AuthModel()
    val getCodeResult = MutableLiveData<Boolean>()
    val thirdPartLoginResult = MutableLiveData<Int>()

    fun getCode(phone: String) {
        RetrofitCall<String?>(lifecycleOwner, this) {
            api { authModel.getCode(phone) }
            success {
                getCodeResult.value = true
            }
            fail { _, _, _ ->
                getCodeResult.value = false
            }
        }
    }

    fun register(phone: String, pwd: String, code: String, inviteCode: String) {
        RetrofitCall<LoginEntity?>(lifecycleOwner, this) {
            api { authModel.register(phone, pwd, code, inviteCode) }
            success {
                thirdPartLoginResult.value = 200
            }
        }
    }
}